/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package deatax.markers;

import deatax.Player;
import deatax.display.BoardRenderer;
import deatax.display.Model;
import deatax.display.ModelLoader;
import deatax.display.Texture;
import deatax.display.particle.AlphaRule;
import deatax.display.particle.ParticleRule;
import deatax.display.particle.ParticleSpawn;
import deatax.display.particle.ScaleRule;
import deatax.display.particle.VectorRule;
import java.awt.Color;
import java.io.FileNotFoundException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.media.opengl.GL2;

/**
 *
 * @author nrechten
 */
public abstract class Marker {
    
    public static Color IDLE_COLOUR = Color.LIGHT_GRAY;
    public static float[] BASE_TOP = genCircle(3, 1);
    public static float[] BASE_BOTTOM = genCircle(3, 2);
    public static float BASE_HEIGHT = 0.1f;
    public static Model base = init();
    
    public final void draw(GL2 gl, int pass){
        switch(pass){
            case 1:
                drawP2(gl);
                break;
            default:
                drawP1(gl);
        }
    }
    protected Player owner;
    
    
    public Marker(Player owner) {
        this.owner = owner;
        
    }
    
    public void drawP1(GL2 gl){
        
    }
    public void drawP2(GL2 gl){
        
    }
    
    public static Model init() {
        Model base = null;
        try {
            base = ModelLoader.loadModel("markers/base.obj");
            //base.setTexture(new Texture("markers/base.jpg"));
            base.setTexture(new Texture("markers/base.png"));
            
//            base.normalise();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(Marker.class.getName()).log(Level.SEVERE, null, ex);
        }
        return base;
    }
    
    public void drawBase(GL2 gl) {
//        init();
        setPlayerColor(gl);
        base.draw(gl);
        gl.glColor3f(1,1,1);

//        gl.glBegin(GL2.GL_TRIANGLE_STRIP);
//        for (int i = 0; i < 13; i += 2) {
//            gl.glVertex3f(BASE_TOP[i % 12], BASE_TOP[i % 12 + 1], BASE_HEIGHT);
//            gl.glVertex2f(BASE_BOTTOM[i % 12], BASE_BOTTOM[i % 12 + 1]);
//        }
//        gl.glEnd();
    }
    
    public void setPlayerColor(GL2 gl) {
        if (owner == null) {
            BoardRenderer.glColor(gl, IDLE_COLOUR);
        } else {
            BoardRenderer.glColorB(gl, owner.getColor());
        }
    }
    
    public static float[] genCircle(int sides, float radius) {
        float[] hex = new float[sides * 8];
        
        for (int i = 0; i < sides * 2; i += 2) {
            hex[i] = Math.abs((float) Math.sin(Math.toRadians(360 / (sides * 2) * i)) * radius);
            hex[i + 1] = Math.abs((float) Math.cos(Math.toRadians(360 / (sides * 2) * i)) * radius);
            hex[i + sides] = -hex[i];
            hex[i + sides + 1] = hex[i + 1];
            hex[i + sides * 2] = hex[i];
            hex[i + sides * 2 + 1] = -hex[i + 1];
            hex[i + sides * 3] = -hex[i];
            hex[i + sides * 3 + 1] = -hex[i + 1];
        }
        return hex;
    }

    public void setOwner(Player owner) {
        this.owner = owner;
    }
    
    
}
